package io.renren.modules.live.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.live.vo.FanweStationMessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.live.entity.FanweStationMessageEntity;
import io.renren.modules.live.service.FanweStationMessageService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 系统消息
 *
 * @author shaoqi
 * @email sunlightcs@gmail.com
 * @date 2020-11-17 09:18:22
 */
@Api(tags = "系统消息管理")
@RestController
@RequestMapping("live/fanwestationmessage")
@Log4j2
public class FanweStationMessageController {
    @Autowired
    private FanweStationMessageService fanweStationMessageService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("live:fanwestationmessage:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = fanweStationMessageService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info")
    //@RequiresPermissions("live:fanwestationmessage:info")
    public R info(@ApiParam(value = "用户ID",required = true) Integer id){
		FanweStationMessageEntity fanweStationMessage = fanweStationMessageService.getById(id);

        return R.ok().put("fanweStationMessage", fanweStationMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("live:fanwestationmessage:save")
    public R save(@RequestBody FanweStationMessageEntity fanweStationMessage){
		fanweStationMessageService.save(fanweStationMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("live:fanwestationmessage:update")
    public R update(@RequestBody FanweStationMessageEntity fanweStationMessage){
		fanweStationMessageService.updateById(fanweStationMessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("live:fanwestationmessage:delete")
    public R delete(@RequestBody Integer[] ids){
		fanweStationMessageService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }
    /**
     * 佟卢海 2020-11-26
     * 管理员查看系统消息列表
     */
    @PostMapping("/selectStationMessageList")
    @RequiresPermissions("sys:StationMessage")
    public R selectStationMessageList(@RequestBody FanweStationMessageVo fanweStationMessageVo){
        R result=new R();
        try{
            if(fanweStationMessageVo.getPageIndex()==null || fanweStationMessageVo.getPageSize() ==null){
                result.put("code",9999);
                result.put("msg","页码页容不能为空！！");
                result.put("data",null);
                return result;
            }
            Map<String, Object> stringObjectMap = fanweStationMessageService.selectStationMessageList(fanweStationMessageVo);
            result.put("data",stringObjectMap);
        }catch (Exception e){
            log.info(e);
            result.put("code",9999);
            result.put("msg","查询失败");
            result.put("data",null);
        }
        return result;
    }
    /**
     * 佟卢海 2020-11-26
     * 管理员查看系统消息
     */
    @GetMapping("/selectStationMessage")
    @RequiresPermissions("sys:StationMessage")
    public R selectStationMessage( String id){
        R result=new R();
        try{
            if(StringUtils.isEmpty(id)){
                result.put("code",9999);
                result.put("msg","id不能为空！！");
                result.put("data",null);
                return result;
            }
            FanweStationMessageEntity fanweStationMessageEntity = fanweStationMessageService.selectStationMessage(id);
            result.put("fanweStationMessageEntity",fanweStationMessageEntity);
        }catch (Exception e){
            log.info(e);
            result.put("code",9999);
            result.put("msg","查询失败");
            result.put("data",null);
        }
        return result;
    }
    /**
     * 佟卢海 2020-11-26
     * 管理员添加或修改系统消息
     */
    @PostMapping("/insertStationMessage")
    @RequiresPermissions("sys:StationMessage")
    public R insertAndupdateStationMessage(@RequestBody FanweStationMessageEntity fanweStationMessageEntity){
        R result=new R();
        try{
            if(StringUtils.isEmpty(fanweStationMessageEntity.getContent()) || fanweStationMessageEntity.getSendTime()==null){
                result.put("code",9999);
                result.put("msg","参数错误！！");
                result.put("data",null);
                return result;
            }
            Integer integer = fanweStationMessageService.insertAndupdateStationMessage(fanweStationMessageEntity);
        }catch (Exception e){
            log.info(e);
            result.put("code",9999);
            result.put("msg","添加失败");
            result.put("data",null);
        }
        return result;
    }
    /**
     * 佟卢海 2020-11-26
     * 管理员查看系统消息
     */
    @GetMapping("/deleteStationMessage")
    @RequiresPermissions("sys:StationMessage")
    public R deleteStationMessage(String id){
        R result=new R();
        try{
            if(StringUtils.isEmpty(id)){
                result.put("code",9999);
                result.put("msg","id不能为空！！");
                result.put("data",null);
                return result;
            }
            Integer integer = fanweStationMessageService.deleteStationMessage(id);
        }catch (Exception e){
            log.info(e);
            result.put("code",9999);
            result.put("msg","查询失败");
            result.put("data",null);
        }
        return result;
    }

}
